/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function (s) {
  let i = 0;
  let l = s.length;
  let j = l - 1;
  let result = '';
  if(!s) {
    return '';
  }
  if(s.length === 1) {
    return s[0];
  }
  for (i = 0; i < l; i++) {
    const ei = s[i];
    for (j=l-1; j > i; j--) {
      const ej = s[j];
      if(ei != ej) {
        continue;
      }
      let subs = s.substring(i, j + 1);
      let isrome = isPalindrome(subs);
      if(isrome) {
        result = subs.length > result.length ? subs : result;
      }
    }
  }
  return result || s[0];
};


function isPalindrome(s) {
  // console.log(s);
  let arr = s.split('');
  let i = 0;
  let j = arr.length - 1;
  while(i < j) {
    let A = arr[i];
    let B = arr[j];
    if (A === B) {
      i++;
      j--;
      continue;
    } else {
      return false;
    }
  }
  return true;
}

// console.time('begin')
// console.log(longestPalindrome("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
// console.timeEnd('begin')

/**
 * @param {number} x
 * @return {boolean}
 */
 var isPalindromeNum = function(x) {
  if(x < 0) {
      return false;
  }
  var str = String(x);
  var stack = [];
  var mid = parseInt(str.length / 2) - 1;
  console.log(mid)
  for(var i = 0;i<=mid;i++) {
      stack.push(str[i]);
  }
  // 奇数长度
  let isOdd = str.length % 2 !== 0;
  let start = 0;
  if(isOdd) {
    start = mid + 2;
  } else {
    start = mid + 1;
  }
  console.log(stack)
  let isrome = true;
  console.log(start)
  for(i = start; i<str.length;i++) {
    let code = stack.pop();
    if(code !== str[i]) {
      isrome = false;
      break;
    }
  }
  return isrome;
};

isPalindromeNum(12021)